﻿'------------------------------
' Hien thi 5 tin moi nhat
'------------------------------
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Namespace NVPortal.Modules.NVBannerAdv

    Public MustInherit Class SettingCustomeDisplaySpecial
        Inherits DotNetNuke.Entities.Modules.ModuleSettingsBase


#Region "Event Handlers"
        Public Overrides Sub LoadSettings()
            Try
                If (Page.IsPostBack = False) Then

                    'BindddlCategories()
                    Dim query As String = "select PortalId, PortalName from PortalLocalization"
                    BindDropDownList(ddlPortal, query, "PortalName", "PortalId", "Chọn trang")
                    ddlvitri.Enabled = True
                    ddlvitri.Items.Insert(0, New ListItem("Chọn danh mục", "0"))

                    If CType(ModuleSettings("PortalSetting"), String) <> "" Then
                        Me.ddlPortal.Items.FindByValue(ModuleSettings("PortalSetting")).Selected = True
                    End If
                    'Bind Danh muc
                    Dim ctlNewsCategories As New NVBannerAdv_VitriController
                    Dim arrNewsCategories As New ArrayList
                    arrNewsCategories = ctlNewsCategories.GetAll(ModuleSettings("PortalSetting"))
                    Me.ddlvitri.DataSource = arrNewsCategories
                    Me.ddlvitri.DataTextField = "Vitri"
                    Me.ddlvitri.DataValueField = "id"
                    Me.ddlvitri.DataBind()
                    'Het
                    If CType(ModuleSettings("NVBannerAdvVitriSetting"), String) <> "" Then
                        Me.ddlvitri.Items.FindByValue(ModuleSettings("NVBannerAdvVitriSetting")).Selected = True
                    End If
                    If CType(ModuleSettings("NVBannerAdvDisplayStyleSetting"), String) <> "" Then
                        Me.ddlDisplayStyle.Items.FindByValue(ModuleSettings("NVBannerAdvDisplayStyleSetting")).Selected = True
                    End If
                End If

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' UpdateSettings saves the modified settings to the Database
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''		[cnurse]	10/22/2004	created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Overrides Sub UpdateSettings()
            Try
                Dim objModules As New DotNetNuke.Entities.Modules.ModuleController
                objModules.UpdateModuleSetting(ModuleId, "PortalSetting", Me.ddlPortal.SelectedValue)
                objModules.UpdateModuleSetting(ModuleId, "NVBannerAdvVitriSetting", Me.ddlvitri.SelectedValue)
                objModules.UpdateModuleSetting(ModuleId, "NVBannerAdvDisplayStyleSetting", Me.ddlDisplayStyle.SelectedValue)


            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Private Sub BindDropDownList(ByVal ddl As DropDownList, ByVal query As String, ByVal text As String, ByVal value As String, ByVal defaultText As String)
            Dim conString As String = ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString
            Dim cmd As New SqlCommand(query)
            Using con As New SqlConnection(conString)
                Using sda As New SqlDataAdapter()
                    cmd.Connection = con
                    con.Open()
                    ddl.DataSource = cmd.ExecuteReader()
                    ddl.DataTextField = text
                    ddl.DataValueField = value
                    ddl.DataBind()
                    con.Close()
                End Using
            End Using
            ddl.Items.Insert(0, New ListItem(defaultText, "0"))
        End Sub
        Protected Sub Country_Changed(ByVal sender As Object, ByVal e As EventArgs)
            ddlvitri.Enabled = False
            ddlvitri.Items.Clear()
            ddlvitri.Items.Insert(0, New ListItem("Select State", "1"))
            Dim countryId As Integer = Integer.Parse(ddlPortal.SelectedItem.Value)
            If countryId > 0 Then
                Dim query As String = String.Format("select id, vitri from NV_BannerAdv_Vitri where PortalId = {0}", countryId)
                BindDropDownList(ddlvitri, query, "Vitri", "id", "Chọn vị trí")
                ddlvitri.Enabled = True
            End If
        End Sub

#End Region


    End Class

End Namespace
